import { JSEncrypt } from 'encryptlong'

const pubKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAXJD28AM//5WszOA7UhWaZ/LzB8IB/cgqo+czTfp1znvCtHHOkrVzmPZArcE1AgafHWI7XBYopeTvopUkhtXcG4jN9zRcZldsO+v4TUryBe4mIfav1gBtHhX6V8l0gIo+9S/vh7h7hhxUN0vO14UL0k7ujhL+OXwgCcGLXh4jkwIDAQAB'

const priKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIBckPbwAz//lazM4DtSFZpn8vMHwgH9yCqj5zNN+nXOe8K0cc6StXOY9kCtwTUCBp8dYjtcFiil5O+ilSSG1dwbiM33NFxmV2w76/hNSvIF7iYh9q/WAG0eFfpXyXSAij71L++HuHuGHFQ3S87XhQvSTu6OEv45fCAJwYteHiOTAgMBAAECgYA0IWPeZetr+mjXHP2UGeocI0tP2D66gE7iwl4LQAgQACPTF2WA96Qppl2cNvTYilIWHODgKq31JCquB+F6TCheAHayn0BSaB2ySUGiWZxhf66IdKqPz62WLHnduFaRPMVBnXt2lwnKHmUfPRo6oAqsw83MyDfTyxJJuBFpYVDggQJBAL/P0GRZANepwSHQXnkIYfDzM5vkAzVfjhg0OdpOxuOp6wm7jWbAl4nMPbE+cJNKs3r4jursGk3IhszWgX8RFAsCQQCrURVeqLYKtvSsMOFbnt5MEsyiqvwXYaRewRsI3U7cI/qixMC/oLMLyU0OnhtNLfzKMYK+bGk9lzx+wQMS5BuZAkEAsl5+W9KoheTGRLuQHt08tuRySbVvhmKlsLxgUDKRoYSRnStcAwF16h6UAA8ggNgmr2QVA0Er9MlVEYcoRRGMoQJAKGkY9Foxjrd3YYKqNfV0lFc+5AQXMOC8aAl++glSB8WI4oosuUcL1PTn81HCOONnJL6nC4oBDSE2iOO4eOVLyQJAIaf6E9s71FCCBypuq5St9PsB8sZnxJEXIUyTkR/rOyAUczFl2IPUuuLeyFUfGI0pGQuBt+qT7xlctlVnArsBWQ=='

/**
 * 是：解密  否：加密
 * @param {boolean} bool
 */
const encrypt = function (data, bool = false) {
  const encryptExample = new JSEncrypt()
  if (bool) {
    encryptExample.setPrivateKey(priKey)
    return decodeURIComponent(encryptExample.decryptLong(data))
  }
  encryptExample.setPublicKey(pubKey)
  return encryptExample.encryptLong(encodeURIComponent(data))
}

export default encrypt
